package br.edu.ufcg.lsd.wbis.ui.client.ui.management;

import br.edu.ufcg.lsd.wbis.ui.client.beans.UserInfo;
import br.edu.ufcg.lsd.wbis.ui.client.services.UserService;
import br.edu.ufcg.lsd.wbis.ui.client.ui.loggedin.util.Refresher;

/**
 * @author Renato Miceli
 */
public class DefaultUserInfoManager extends GenericInfoManager<UserInfo> {

	private final Refresher<DefaultUserInfoManager> timer;

	public DefaultUserInfoManager(UserInfo info) {
		super(info);

		timer = getRefresher();
	}

	public void start() {
		timer.run();
		defaultSchedule();
	}

	protected Refresher<DefaultUserInfoManager> getRefresher() {
		return new Refresher<DefaultUserInfoManager>(this) {

			@Override
			public void run() {
				final UserInfo info = getInfo();
				if (info != null && info.getLogin() != null) {
					UserService.Util.getInstance().getUserInfo(info.getLogin(), info.getPassword(), info.getLogin(),
							new UserInfoUpdaterCallback(getRefreshableObject()));
				}
			}

		};
	}

	/**
	 * {@inheritDoc}
	 */
	public void defaultSchedule() {
		timer.defaultSchedule();
	}

	/**
	 * {@inheritDoc}
	 */
	public void defaultCancel() {
		timer.defaultCancel();
	}

}
